var my_damage=0;
var enemy_damage=0;

var k=0;
var hand_new="";

var click_id="";
var temp_click_id="";

var wait=0;
var attack_permission=0;
var event=0;
var operation_permission=0;

msg_boxs.style.width="200px";
msg_boxs.style.height="50px";
setTimeout(function()
		{
			msg_box("     ");
			jj=1;
		}
		,4000);
aaa.style.height="350px";
bbb.style.height="350px";

my_desk.style.bottom="20px";
my_desk.style.right="20px";
var jj=0;

function charge()
{
	if (myself.life_value<=0 || myself.desk_number<=0)
	{
		msg_box("你输啦！");
	};
	if (enemy.life_value<=0 || enemy.desk_number<=0)
	{
		msg_box("你赢啦！");
	};
};

function interview(card_id)
{
	var temp_card=get_card(card_id);
	document.getElementById("interview_img").src=temp_card.img_src;
	if (temp_card.type=="monster")
	{
		var temp_stars=temp_card.stars;
		var monster_stars="";
		while (temp_stars > 0)
		{
			monster_stars+="✪";
			temp_stars-=1;
		}
		document.getElementById("stars").innerHTML=monster_stars;
		document.getElementById("card_name").innerHTML=temp_card.name;
		document.getElementById("property").innerHTML=temp_card.property;
		document.getElementById("type").innerHTML="["+temp_card.race+"/"+temp_card.hypo_type+"]";
		document.getElementById("value_text").innerHTML=temp_card.value_text;
		document.getElementById("attack_defend").innerHTML="ATK/"+temp_card.attack+"&nbsp&nbsp"+"DEF/"+temp_card.defend;
	}	
	else
	{
		document.getElementById("stars").innerHTML="";
		document.getElementById("card_name").innerHTML=temp_card.name;
		document.getElementById("type").innerHTML="["+temp_card.hypo_type+"]";
		document.getElementById("value_text").innerHTML=temp_card.value_text;
		document.getElementById("attack_defend").innerHTML="";
		document.getElementById("property").innerHTML="";
	}
};

function get_card_id_from_box(card_box_id)
{
	var temp_box=eval(card_box_id);
	if (card_box_id[3]=="m" || card_box_id[3]=="c")
	{
		var card_id=temp_box.id;
	}
	else
	{
		var list_order=card_box_id[card_box_id.length -1];
		var card_id=myself.hand_list[list_order-1];
	}
	return card_id;
}

function turn(card_box_id,turn_type)
{
	if (operation_permission==1)
	{
		card_id=get_card_id_from_box(card_box_id);
		var temp_box=eval(card_box_id);
		var temp_card=get_card(card_id);
		if (temp_card.type=="monster")
		{var temp_turn=document.getElementById("m_"+card_id+"_"+temp_box.order);}
		else
		{var temp_turn=document.getElementById("t_"+card_id+"_"+temp_box.order);}
		if (temp_box.turn_permission==1 || card_box_id.substr(3,3)!="mon")
		{
			if (turn_type=="attack")
			{
				if (temp_box.turn=="cover")
					{
						scale_card(card_id);
						temp_summon=temp_card.event;
						if (temp_summon==0)
						{
							msg_box("反转召唤"+temp_card.name+"!");
						}
						else
						{
							if (temp_summon.substr(-4,4)==".mp4")
							{
								setTimeout(function(){video(temp_summon)},1300);
							}
							else
							{
								msg_box(temp_card.event);
							}
						}
					};
				temp_turn.style.transform="rotate(0deg)";
				temp_turn.src=temp_card.img_src;
			};
			if (turn_type=="defend")
			{
				temp_turn.style.transform="rotate(90deg)";
				temp_turn.src=temp_card.img_src;
			};
			if (turn_type=="cover")
			{
				temp_turn.style.transform="rotate(90deg)";
				temp_turn.src="img/cover.jpg";
			};
			if (turn_type=="mg_face")
			{
				scale_card(card_id);
				temp_turn.style.transform="rotate(0deg)";
				temp_turn.src=temp_card.img_src;
			};
			if (turn_type=="mg_cover")
			{
				temp_turn.style.transform="rotate(0deg)";
				temp_turn.src="img/cover.jpg";
			};
			temp_box.turn=turn_type;
		}
		temp_box.turn_permission=0;
	}
};

function my_life(my_damage)
{
	myself.life_value+=my_damage;
	if (myself.life_value>0)
	{my_life_standard=350*(myself.life_value/8000);}
	else{myself_life_standard=0;}
	if (my_damage>0)
	{
		var damage_text="+"+my_damage;
	}
	if (my_damage==0)
	{
		var damage_text="";
	}
	if (myself.life_value>0){msg_box("我方生命值"+my_damage+"&nbsp&nbsp"+"剩余"+myself.life_value);}

	aaa.style.height=my_life_standard+"px";
	if (myself.life_value<=4000 && myself.life_value>3000)
	{
		aaa.style.background="#ff6f22";
	}
	if (myself.life_value<=3000)
	{
		aaa.style.background="#ec2525";
		bgm("img2/arranged.mp3");
	}
	charge();
};

function enemy_life(enemy_damage)
{
	enemy.life_value+=enemy_damage;
	if (enemy.life_value>0)
	{enemy_life_standard=350*(enemy.life_value/8000);}
	else{enemy_life_standard=0;}
	if (enemy_damage>0)
	{
		var damage_text="+"+enemy_damage;
	}
	if (enemy_damage==0)
	{
		var damage_text="";
	}
	if (enemy.life_value>0){msg_box("敌方生命值"+enemy_damage+"&nbsp&nbsp"+"剩余"+enemy.life_value);};

	bbb.style.height=enemy_life_standard+"px";
	if (enemy.life_value<=4000 && enemy.life_value>3000)
	{
		bbb.style.background="#a638f3";
	}
	if (enemy.life_value<=3000)
	{
		bbb.style.background="#ec2525";
	}
	charge();
};

function msg_box(msg)
{
	var temp_msg=document.getElementById("msg");
	if (msg.substr(-4,4)==".gif")
	{
		msg_boxs.style.background="url("+msg+")";
		temp_msg.innerHTML="    ";
		msg_boxs.style.height="280px";
		msg_boxs.style.width="500px";
		msg_boxs.style.padding="0px";
		setTimeout(
			function()
			{
				msg_box("     ");
				jj=1;
			}
		,4000);
	}
	else
	{
		temp_msg.innerHTML=msg;

  		var len = 0;
            for (var i = 0; i < msg.length; i++) {
                var a = msg.charAt(i);
                if (a.match(/[^\x00-\xff]/ig) != null) {
                    len += 2;
                }
                else {
                    len += 1;
                }
            }
		width=len*10;
		msg_boxs.style.background="";
		msg_boxs.style.height="50px";
		msg_boxs.style.width=width+"px";
	}
	if(msg=="你赢啦！" || msg=="你输啦！")
	{
		msg_boxs.style.width="490px";
		msg_boxs.style.height="730px";
		document.getElementById("msg_boxs").innerHTML="<img id=\"win1\" src=\"img2/youwin.png\" style=\"position:absolute;top:0px;left:0px;transition:all 2s;-webkit-transition:all 2s\"><img id=\"win2\" src=\"img2/youwin2.png\" style=\"position:absolute;top:0px;left:0px\">"
		msg_boxs.style.top="50%";
		msg_boxs.style.left="50%";
		msg_boxs.style.transform="translate(-50%,-50%)";
		setTimeout(function(){msg_boxs.style.transition="transform 3s";},500);		
		msg_boxs.onmouseover=function()
		{
			msg_boxs.style.transform="translate(-50%,-50%) rotateY(-30deg) rotateX(-10deg)";
		}
		msg_boxs.onmouseout=function()
		{
			msg_boxs.style.transform="translate(-50%,-50%) rotateY(0deg) rotateX(0deg)";
		}
		duel.style.filter="blur(20px)";
		duel.style.webkitFilter="blur(20px)";
		shark();
	}	
};

function shark()
{
	win1.style.filter="brightness(1.5)";
	win1.style.webkitFilter="brightness(1.5)";
	setTimeout(function(){
		win1.style.filter="brightness(1)";
		win1.style.webkitFilter="brightness(1)";
		setTimeout(function(){
			shark();
		},2000)
	},2000)
}

function test(msg)
{
	window.alert(msg);
};

function into_cemetery(card_box_id)
{
	if (card_box_id.substr(0,2)=="my")
	{
		var card_id=get_card_id_from_box(card_box_id);
		temp_card=get_card(card_id);
		myself.cemetery_list.splice(0,0,card_id);
		myself.cemetery_number++;
		var temp_box=eval(card_box_id);
		var type=temp_box.type;
		if (type=="m_")
		{myself.monster_number--}
		else
		{myself.turn_number--}
		document.getElementById(card_box_id).innerHTML="";
		move("none",card_box_id,"cemetery");
		setTimeout(function(){
			document.getElementById("cemetery").src=temp_card.img_src;
			move_box.style.transition="transform 0s";
			move_box.style.transform="translate(1000px,1000px) rotate(0deg)";
			document.getElementById("move_box").innerHTML="";
		},300)
		card_break(card_box_id);
	}
	else
	{
		var card_id=get_card_id_from_box(card_box_id);
		temp_card=get_card(card_id);
		enemy.cemetery_list.splice(0,0,card_id);
		enemy.cemetery_number++;
		enemy.monster_number--;
		document.getElementById(card_box_id).innerHTML="";
		move("none",card_box_id,"cemetery2");
		setTimeout(function(){
			document.getElementById("cemetery2").src=temp_card.img_src;
			move_box.style.transition="transform 0s";
			move_box.style.transform="translate(1000px,1000px) rotate(0deg)";
			document.getElementById("move_box").innerHTML="";
		},300)
		card_break(card_box_id);
	}
};

function clear_box(card_box_id)
{
	var temp_box=eval(card_box_id);
	temp_box.t=0;
	temp_box.id="";
	temp_box.condition=1;
	temp_box.turn="";
	temp_box.link=new Array();
	temp_box.dt="";
};

function card_break(card_box_id)
{
	var card_id=get_card_id_from_box(card_box_id);
	clear_box(card_box_id);
	document.getElementById(card_box_id).innerHTML="";
};

function summon(card_box_id,card_box_id_old,summon_type)
{
	if(operation_permission==1 && summon_permission==1){
	//获取格子对象与卡片ID
	temp_box=eval(card_box_id);
	var card_id=get_card_id_from_box(card_box_id_old);
	temp_card=get_card(card_id);
	//更新格子对象信息
	temp_box.turn=summon_type;
	temp_box.t=1;
	temp_box.id=card_id;
	temp_box.attack=temp_card.attack;
	temp_box.defend=temp_card.defend;
	temp_box.stars=temp_card.stars;
	myself.monster_number++;
	temp_card.point(card_box_id);
	//执行出牌动画
	move(card_box_id,card_box_id_old,summon_type);
	//0.5s后在怪兽格子处写入怪兽卡
	setTimeout(function(){
		if (summon_type == "attack")
		{
			document.getElementById(card_box_id).innerHTML="<img id=\"m_"+card_id+"_"+temp_box.order+"\" src=\"img/"+card_id+".jpg\" class=\"card\" onmouseover=\"interview('"+card_id+"');if (summon_state==0){this.style.border='2px solid #fff';}\" onmouseout=\"if (summon_state==0){this.style.border='0px solid #fff';}\"><div class=\"at_df\">"+temp_card.attack+" "+temp_card.defend+"</div>";
		}
		else if (summon_type == "defend")
		{
			document.getElementById(card_box_id).innerHTML="<img id=\"m_"+card_id+"_"+temp_box.order+"\" src=\"img/"+card_id+".jpg\" class=\"card\" style=\"transform:rotate(90deg)\" onmouseover=\"interview('"+card_id+"');if (summon_state==0){this.style.border='2px solid #fff'}\" onmouseout=\"if (summon_state==0){this.style.border='0px solid #fff'}\"><div class=\"at_df\">"+temp_card.attack+" "+temp_card.defend+"</div>";
		}
		else if (summon_type == "cover")
		{
			document.getElementById(card_box_id).innerHTML="<img id=\"m_"+card_id+"_"+temp_box.order+"\" src=\"img/cover.jpg\" class=\"card\" style=\"transform:rotate(90deg)\" onmouseover=\"interview('"+card_id+"');if (summon_state==0){this.style.border='2px solid #fff'}\" onmouseout=\"if (summon_state==0){this.style.border='0px solid #fff';}\"><div class=\"at_df\">"+temp_card.attack+" "+temp_card.defend+"</div>";
		}
	//并 重置出牌动画
	document.getElementById("move_box").innerHTML="";
	move_box.style.transition="transform 0s";
	move_box.style.transform="translate(1000px,1000px)  rotate(0deg)";
	},500);
	//在格子对象更新卡片信息
	temp_box.dt=document.getElementById(card_box_id).innerHTML;
	//手卡消失动画
	eval(card_box_id_old+".style.width=\"0px\"");
	//手卡格子清空
	document.getElementById(card_box_id_old).innerHTML="";
	setTimeout(function(){
	var hand_order=card_box_id_old[13];
	var my_hand_temp=document.getElementById("my_hand");
	var my_hand_card_temp=document.getElementById(card_box_id_old);
	my_hand_temp.removeChild(my_hand_card_temp);
	//刷新手卡
	
		myself.hand_number--;
		var new_hand_order=parseInt(hand_order)-1;
		myself.hand_list.splice(new_hand_order,1);
		refresh(card_box_id_old);			
	},500);
	//卡片放大动画
	if (summon_type!="cover")
	{scale_card(card_id);};}
	//处理召唤特殊事件
	temp_summon=temp_card.event;
	if (temp_summon!=0)
	{
		if (temp_summon.substr(-4,4)==".gif" || temp_summon.substr(-4,4)==".jpg" || temp_summon.substr(-4,4)==".png" || temp_summon.substr(-4,4)==".mp4")
		{
			if (summon_type!="cover")
			{
				if (temp_summon.substr(-4,4)==".mp4")
				{
					setTimeout(function(){video(temp_summon)},1300);
				}
				else
				{msg_box(temp_card.event);}
			}
		}
	}
	else
	{
		if (summon_type == "attack")
		{
			var summon_type_text="攻击表示";
		}
		else if (summon_type == "defend")
		{
			var summon_type_text="防御表示";
		}
		else if (summon_type == "cover")
		{
			var summon_type_text="里侧表示";
		}
		msg_box("我以"+summon_type_text+"召唤"+temp_card.name+"!");
	}
};

function summon_sacrifice(card_id)
{
	var temp_card=get_card(card_id);
	var stars=temp_card.stars;
	if (stars<=4)
	{
		return 0;
	}
	else if (4<stars && stars<=6)
	{
		return 1;
	}
	else
	{
		return 2;
	}
}

var summon_choose=new Array();
var sacrifice_num=0;
var summon_ifm=new Array();
var summon_state=0;
var summon_permission=1;
function summon_(card_box_id,card_box_id_old,summon_type)
{
	if (operation_permission==1 && summon_permission==1)
	{
		var card_id=get_card_id_from_box(card_box_id_old);
		sacrifice_num=summon_sacrifice(card_id);
		if (sacrifice_num>myself.monster_number)
		{
			return;
		}
		else if (sacrifice_num==0)
		{
			summon(card_box_id,card_box_id_old,summon_type);
			summon_permission=0;
			return;
		}
		var temp_card=get_card(card_id);
		summon_ifm=[card_box_id,card_box_id_old,summon_type];
		summon_state=1;
		for (var index=0;index<5;index++)
		{
			var temp_card2=eval("my_monster_"+(index+1));
			if (temp_card2.t==1)
			{
				document.getElementById("m_"+temp_card2.id+"_"+(index+1)).style.border="dashed 2px orange";
				document.getElementById("m_"+temp_card2.id+"_"+(index+1)).onclick=function()
				{
					var id=this.id;
					this.style.border="solid 5px orange";
					id="my_monster_"+parseInt(id.substr(-1,1));
					summon_choose.splice(0,0,id);
					if (summon_choose.length==sacrifice_num)
					{
						mul_into_cemetery(summon_choose);
						end_summon();
						setTimeout(function(){summon(summon_ifm[0],summon_ifm[1],summon_ifm[2]);summon_permission=0},600);
					}
				}
			}
		}
	}
}

function mul_into_cemetery(list)
{
	for (var ce=0;ce<list.length;ce++)
	{
		into_cemetery(list[ce]);
	}
}

function end_summon()
{
	summon_state=0;
	summon_choose=new Array();
	for (var index2=0;index2<5;index2++)
	{
		var temp_card3=eval("my_monster_"+(index2+1));
		if (temp_card3.t==1)
		{
			document.getElementById("m_"+temp_card3.id+"_"+(index2+1)).style.border="solid 0px #fff";
			document.getElementById("m_"+temp_card3.id+"_"+(index2+1)).onclick=function(){return;};
		}
	}
}

function get_card(card_id)
{
	return eval("card_"+card_id);
};

var draw_point_list=[];
function draw(num)
{
	if (num>0)
	{
		num--;
		my_hand.style.transition="left 0.5s";
		var draw_card=myself.desk_list[0];
		myself.desk_list.splice(0,1);
		myself.desk_number--;
		myself.hand_number++;
		myself.hand_list.splice(myself.hand_number,0,draw_card);
		var temp_draw=document.getElementById("my_hand").innerHTML;
		temp_draw+=
		"<div id=\"my_hand_card_"+myself.hand_number+"\" class='hand_box' onclick=\"click_ansys('my_hand_card_"+myself.hand_number+"')\"><img id=\"h_"+draw_card+"_"+myself.hand_number+"\" src=\"img/"+draw_card+".jpg\" class=\"card_hand\" onmouseover=\"interview('"+draw_card+"')\"></div>";
		draw_effect();
		setTimeout
		(
			function()
			{
				document.getElementById("my_hand").innerHTML=temp_draw;
				reset_draw();
				if (num>0)
				{
					setTimeout
					(
						function()
						{
							draw(num);
							for (var index=0;index<draw_point_list.length;index++)
							{
								var box_id=draw_point_list[index];
								var temp_box=eval(box_id);
								var card_id=temp_box.id;
								var temp_card=get_card(card_id);
								temp_card.value(box_id);
							}
						},
						400
					);				
				};
				my_hand.style.transition="left 0s";
				my_hand.style.left="0px";
			},
			400
		);
		
	};
};

function set_card(card_box_id,card_box_id_old)
{
	if (operation_permission==1){
	//获取格子对象与卡片ID
	var card_id=get_card_id_from_box(card_box_id_old);
	var temp_card=get_card(card_id);
	var temp_box=eval(card_box_id);
	//盖牌的<img>标签
	temp_set="<img id=\"t_"+card_id+"_"+temp_box.order+"\" src=\"img/cover.jpg\" class=\"card\" onmouseover=\"interview('"+card_id+"'),this.style.border='2px solid #fff';\" onmouseout=\"this.style.border='0px solid #fff';\">";
	//出牌动画
	move(card_box_id,card_box_id_old,"mg_cover");
	//将手卡格子宽度变为0
	eval(card_box_id_old+".style.width=\"0px\"");
	//清空图片内容
	document.getElementById(card_box_id_old).innerHTML="";
	//0.5s后在格子处盖牌并重置出牌动画
	setTimeout(function(){document.getElementById(card_box_id).innerHTML=temp_set;move_box.style.transition="transform 0s";
	move_box.style.transform="translate(1000px,1000px)  rotate(0deg)";document.getElementById("move_box").innerHTML="";},500);
	//更新格子对象信息
	temp_box.t=1;
	temp_box.id=card_id;
	temp_box.turn="mg_cover";
	//删除手卡空格子
	setTimeout(function(){
	var hand_order=card_box_id_old[13];
	var my_hand_temp=document.getElementById("my_hand");
	var my_hand_card_temp=document.getElementById(card_box_id_old);
	my_hand_temp.removeChild(my_hand_card_temp);
	//test(hand_new);
	//刷新手卡
	
		myself.hand_number--;
		var new_hand_order=parseInt(hand_order)-1;
		myself.hand_list.splice(new_hand_order,1);
		refresh(card_box_id_old);	
	},500);}
}

function execute_card(card_box_id,card_box_id_old)
{
	//获取格子对象与卡片ID
	var card_id=get_card_id_from_box(card_box_id_old);
	var temp_card=get_card(card_id);
	var temp_box=eval(card_box_id);
	//盖牌的<img>标签
	temp_set="<img id=\""+temp_box.type+card_id+"_"+temp_box.order+"\" src=\"img/"+card_id+".jpg\" class=\"card\" onmouseover=\"interview('"+card_id+"'),this.style.border='2px solid #fff';\" onmouseout=\"this.style.border='0px solid #fff';\">";
	//出牌动画
	move(card_box_id,card_box_id_old,"mg_execute");
	//将手卡格子宽度变为0
	eval(card_box_id_old+".style.width=\"0px\"");
	//清空图片内容
	document.getElementById(card_box_id_old).innerHTML="";
	//0.5s后在格子处盖牌并重置出牌动画
	setTimeout(function(){document.getElementById(card_box_id).innerHTML=temp_set;move_box.style.transition="transform 0s";
	move_box.style.transform="translate(1000px,1000px) rotate(0deg)";document.getElementById("move_box").innerHTML="";},500);
	//更新格子对象信息
	temp_box.t=1;
	temp_box.id=card_id;
	temp_box.turn="mg_cover";
	//删除手卡空格子
	setTimeout(function(){
	var hand_order=card_box_id_old[13];
	var my_hand_temp=document.getElementById("my_hand");
	var my_hand_card_temp=document.getElementById(card_box_id_old);
	my_hand_temp.removeChild(my_hand_card_temp);
	//test(hand_new);
	//刷新手卡
	myself.hand_number--;
	var new_hand_order=parseInt(hand_order)-1;
	myself.hand_list.splice(new_hand_order,1);
	refresh(card_box_id_old);	
	},500);
}

function change_size()
{
	if  (jj==0)
	{
		msg_box("    ");
		jj++;
	}
	else
	{
		msg_box("        ");
		jj--;
	}
};

function draw_effect()
{

	my_desk.style.bottom="-104px";
	my_desk.style.right=0.5*(1050-(myself.hand_number+1)*110)+"px";
	my_desk.style.transform="rotateY(90deg)";
	my_hand.style.left="-55px";
};

function reset_draw()
{
	document.getElementById("reset").innerHTML="<div style=\"position:absolute\" class=\"my_desk\" id=\"my_desk\"><img src=\"img/cover.jpg\" class=\"card\" onmouseover=\"my_desk.style.bottom='0px';\" onmouseout=\"my_desk.style.bottom='20px'\"></div>";
}

function scale_card(card_id)
{
	max_img_box.style.background="url('img/"+card_id+".jpg')";
	max_img_box.style.height="254px";
	setTimeout
	(
		function()
		{
			max_img_box.style.height="0px";
		},1000
	)
};

function msg_box2(msg)
{
	max_img_box.style.background="";
	max_img_box.style.width="300px";
	max_img_box.style.height="100px";
	max_img_box.style.color="#fff";
	max_img_box.style.backgroundColor="rgba(0,0,0,0.7)";
	max_img_box.style.transform="translate(0px,-50px)";
	max_img_box.style.boxShadow="0px 0px 0px #fff";
	max_img_box.style.borderRadius="20px";
	document.getElementById("max_img_box").innerHTML=msg;
	setTimeout(function(){
		max_img_box.style.backgroundColor="";
		max_img_box.style.color="rgba(0,0,0,0.7)";
		max_img_box.style.transform="translate(88px,-127px)";
		max_img_box.style.width="177px";
		max_img_box.style.height="0px";
		max_img_box.style.borderRadius="0px";
		document.getElementById("max_img_box").innerHTML="";
		setTimeout(function(){
			max_img_box.style.boxShadow="20px 20px 200px #000";
		},400);
	},500)
}

function distance_index(card_box_id)
{
//这个函数用于根据传入格子ID判断其离中心的距离	
	//判断是否是怪兽格子或者魔法陷阱格子
	if (card_box_id.substr(3,3)=="mon")
	{
		//获取格子索引值
		var box_index=parseInt(card_box_id[11]);
		//需要右移的距离（负号为左移）
		var distance=160*(box_index-3);
	}
	if (card_box_id.substr(3,3)=="cov")
	{
		//获取格子索引值
		var box_index=parseInt(card_box_id[9]);
		//需要右移的距离（负号为左移）
		var distance=160*(box_index-3);
	}
	//手卡格子
	if (card_box_id.substr(3,3)=="han")
	{
		var box_index=parseInt(card_box_id[13]);
		//如果手卡数是奇数
		if (myself.hand_number%2==1)
		{
			var distance=(box_index-0.5*(myself.hand_number+1))*110;
		}
		//偶数
		else
		{
			//加1法
			var distance=(box_index-(0.5*(myself.hand_number+2)-0.5))*110;
		}
	}
	if (card_box_id.substr(6,3)=="mon")
	{
		//获取格子索引值
		var box_index=parseInt(card_box_id[14]);
		//需要右移的距离（负号为左移）
		var distance=160*(box_index-3);
	}
	if (card_box_id.substr(6,3)=="cov")
	{
		//获取格子索引值
		var box_index=parseInt(card_box_id[12]);
		//需要右移的距离（负号为左移）
		var distance=160*(box_index-3);
	}
	//手卡格子
	if (card_box_id.substr(6,3)=="han")
	{
		var box_index=parseInt(card_box_id[16]);
		//如果手卡数是奇数
		if (myself.hand_number%2==1)
		{
			var distance=(box_index-0.5*(myself.hand_number+1))*110;
		}
		//偶数
		else
		{
			//加1法
			var distance=(box_index-(0.5*(myself.hand_number+2)-0.5))*110;
		}
	}
	return distance;
}

function move(card_box_id,card_box_id_old,turn_type)
{
	//获取卡片ID 传入格子对象、卡片对象
	var card_id=get_card_id_from_box(card_box_id_old);
	if (card_box_id!="none"){
	var temp_box=eval(card_box_id);}
	var temp_box2=eval(card_box_id_old);
	//根据召唤表示形式选择旋转角度
	if (turn_type=="attack")
	{
		var distance=distance_index(card_box_id_old);
		move_box.style.transform="translate("+(90+distance)+"px,325px)";
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/"+card_id+".jpg' style='width:100px;height:150px'>";
			move_box.style.transition="transform 0.5s";
			move_box.style.transform="translate("+(90+(temp_box.order-3)*160)+"px,10px)";
		},1);
	};

	if (turn_type=="defend")
	{
		var distance=distance_index(card_box_id_old);
		move_box.style.transform="translate("+(90+distance)+"px,325px) rotate(0deg)";
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/"+card_id+".jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.5s all";
			move_box.style.transform="translate("+(90+(temp_box.order-3)*160)+"px,10px) rotate(90deg)";
		},1);
	}

	if (turn_type=="cover")
	{
		var distance=distance_index(card_box_id_old);
		move_box.style.transform="translate("+(90+distance)+"px,325px) rotate(0deg)";
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/cover.jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.5s all";
			move_box.style.transform="translate("+(90+(temp_box.order-3)*160)+"px,10px) rotate(90deg)";
		},1);
	}

	if (turn_type=="mg_cover")
	{
		var distance=distance_index(card_box_id_old);
		move_box.style.transform="translate("+(90+distance)+"px,325px) rotate(0deg)";
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/cover.jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.5s all";
			move_box.style.transform="translate("+(90+(temp_box.order-3)*160)+"px,165px) rotate(0deg)";
		},1);
	}
	if (turn_type=="mg_execute")
	{
		var distance=distance_index(card_box_id_old);
		move_box.style.transform="translate("+(90+distance)+"px,325px) rotate(0deg)";
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/"+card_id+".jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.5s all";
			move_box.style.transform="translate("+(90+(temp_box.order-3)*160)+"px,165px) rotate(0deg)";
		},1);
	}
	if (turn_type=="cemetery")
	{
		var card_id=get_card_id_from_box(card_box_id_old);
		var distance=distance_index(card_box_id_old);
		if (card_box_id_old.substr(3,3)=="mon")
		{
			move_box.style.transform="translate("+(90+distance)+"px,10px) rotate(0deg)";
		};
		if (card_box_id_old.substr(3,3)=="cov")
		{
			move_box.style.transform="translate("+(90+distance)+"px,165px) rotate(0deg)";
		};
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/"+card_id+".jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.3s all";
			move_box.style.transform="translate(545px,40px) rotate(0deg)";
		},1);
	}
	if (turn_type=="cemetery2")
	{
		var card_id=get_card_id_from_box(card_box_id_old);
		var distance=distance_index(card_box_id_old);
		if (card_box_id_old.substr(6,3)=="mon")
		{
			move_box.style.transform="translate("+((-1)*(90+distance))+"px,-140px) rotate(180deg)";
		};
		if (card_box_id_old.substr(6,3)=="cov")
		{
			move_box.style.transform="translate("+((-1)*(90+distance))+"px,-165px) rotate(180deg)";
		};
		setTimeout(function(){
			document.getElementById("move_box").innerHTML="<img src='img/"+card_id+".jpg' style='width:100px;height:150px'>";
			move_box.style.transition="0.3s all";
			move_box.style.transform="translate(-370px,-195px) rotate(180deg)";
		},1);
	}
}

function refresh(card_box_id)
{
	var hand_number=myself.hand_number;
	var hand_number_i=card_box_id[13];
	var temp_hand=document.getElementById("my_hand").innerHTML;
	while (hand_number_i<=hand_number)
	{

		var hand_number_j=parseInt(hand_number_i)+1;
		var m1="id=\"my_hand_card_"+hand_number_j+"\"";
		var m2="id=\"my_hand_card_"+hand_number_i+"\"";
		temp_hand=temp_hand.replace(m1,m2);
		n0=parseInt(hand_number_i)-1;
		var card_id=myself.hand_list[n0];
		var n1="id=\"h_"+card_id+"_"+hand_number_j+"\"";
		var n2="id=\"h_"+card_id+"_"+hand_number_i+"\"";
		temp_hand=temp_hand.replace(n1,n2);
		var j1="click_ansys('my_hand_card_"+hand_number_j+"')";
		var j2="click_ansys('my_hand_card_"+hand_number_i+"')";
		temp_hand=temp_hand.replace(j1,j2);
		hand_number_i=hand_number_j;
	}
	document.getElementById("my_hand").innerHTML=temp_hand;
}

function bgm(bgm_src)
{
	document.getElementById("bgm_box").src=bgm_src;
	document.getElementById("bgm_box").volume=0.3;
	bgm_box.play();
}

var msg_temp="";
function video(video_src)
{
	var msg_temp=document.getElementById("msg_boxs").innerHTML;
	document.getElementById("msg_boxs").innerHTML="<video src='"+video_src+"' id='event_video'  style='height:680px;width:1000px;position:absolute;top:-100px;left:0px'></video>";
	event_video.play();
	duel.style.filter="blur(20px)";
	duel.style.webkitFilter="blur(20px)";
	//turn_dark();
	msg_boxs.style.width="990px";
	msg_boxs.style.height="450px";
	msg_boxs.style.top="50%";
	msg_boxs.style.right="50%";

	msg_boxs.style.transform="translate(50%,-50%)";
	var temp_msg_box=document.getElementById('msg_boxs');
	temp_msg_box.onmouseover=function(){};		
	temp_msg_box.onmouseout=function(){};
	var video_ = document.getElementById("event_video");
	video_.addEventListener('ended', function () { 
	msg_boxs.style.width="50px";
	msg_boxs.style.height="50px";
	msg_boxs.style.top="20px";
	msg_boxs.style.right="20px"; 		
	msg_boxs.style.transform="translate(0px,0px)";
	temp_msg_box.onmouseover=function(){this.style.transform='translate(-10px,0px)'};		
	temp_msg_box.onmouseout=function(){this.style.transform='translate(0px,0px)'};
	document.getElementById("msg_boxs").innerHTML=msg_temp;
	duel.style.filter="blur(0px)";
	duel.style.webkitFilter="blur(0px)";
	msg_box("    ");
	jj=1;
	}, false);
};

function turn_dark()
{
	dark.style.width="10000px";
	dark.style.height="10000px";
	dark.style.opacity="0.5";
}

function turn_light()
{
	dark.style.width="0px";
	dark.style.height="0px";
	dark.style.opacity="0";
}

function get_card_id_from_hand(hand_id)
{
	var hand_order=parseInt(hand_id[13]);
	hand_index=hand_order-1;
	var card_id=myself.hand_list[hand_index];
	return card_id;
}

function execute(card_box_id)
{
	if (card_box_id.substr(3,3)=="han")
	{
		var card_id=get_card_id_from_hand(card_box_id);
	}
	else
	{
		var card_id=get_card_id_from_box(card_box_id);
	}
	var temp_card=get_card(card_id);
	temp_card.value();
}

function attack(card_box_id_myself,card_box_id_enemy)
{
	if (attack_permission==1)
	{
		var card_id_1=get_card_id_from_box(card_box_id_myself);
		var temp_card_1=get_card(card_id_1);
		var card_id_2=get_card_id_from_box(card_box_id_enemy);
		var temp_card_2=get_card(card_id_2)
		var temp_box_1=eval(card_box_id_myself);
		var temp_box_2=eval(card_box_id_enemy);
		if (temp_box_1.attack_permission==1)
		{
			if (temp_box_1.turn=="attack")
			{
				if (temp_box_2.turn=="attack")
				{
					if (temp_box_1.attack>temp_box_2.attack)
					{
						into_cemetery(card_box_id_enemy);
						var enemy_damage=temp_box_2.attack-temp_box_1.attack;
						enemy_life(enemy_damage);
						msg_box2(enemy_damage);
					}
					if (temp_box_1.attack==temp_box_2.attack)
					{
						into_cemetery(card_box_id_enemy);
						into_cemetery(card_box_id_myself);
					}
					if (temp_box_1.attack<temp_box_2.attack)
					{
						into_cemetery(card_box_id_myself);
						var myself_damage=temp_box_1.attack-temp_box_2.attack;
						my_life(myself_damage);
						msg_box2(myself_damage);
					}
				}

				else
				{
					if (card_box_id_enemy.turn=="cover")
					{
						turn(card_box_id_enemy,"defend");
					}
					if (temp_box_1.attack>temp_box_2.defend)
					{
						into_cemetery(card_box_id_enemy);
					}
					else
					{
						var myself_damage=temp_box_1.attack-temp_box_2.defend;
						my_life(myself_damage);
						msg_box2(myself_damage);
					}
				}
			}
			temp_box_1.attack_permission=0;
			temp_box_1.turn_permission=0;
		}
	}
}

function auto_step_1()
{
	for (var i=1;i<6;i++)
	{
		eval("my_monster_"+i+".turn_permission=1");
		eval("my_monster_"+i+".attack_permission=1");
	}
	system.step==0;
	if (event==0)
	{
		setTimeout(function(){
			system.step=1;
			msg_box2(system.step_text[system.step]);
			draw(1);
			if (event==0)
			{
				setTimeout(function(){
				system.step=2;
				msg_box2(system.step_text[system.step]);
				operation_permission=1;
				attack_permission=0;
				},1000)
			}
		},1000)
	}
}

function attack_step()
{
	if (system.step==2)
	{
		system.step=3;
		setTimeout(function(){msg_box2(system.step_text[system.step])},200);
		operation_permission=0;
		attack_permission=1;
	}
}

function main_step_2()
{
	if (system.step==3)
	{
		system.step=4;
		setTimeout(function(){msg_box2(system.step_text[system.step])},200);
		operation_permission=1;
		attack_permission=0;
	}
}

function auto_step_2()
{
	if (event==0)
	{
		setTimeout(function(){
			system.step=5;
			msg_box2(system.step_text[system.step]);
		},500)
	}
}
$(document).ready(function(){
	//fix_size();
	$("#triangle").hide();
	$("#flex_menu").hide();
	$("div").click(function click_guard(){
		temp_click_id=$(this).attr("id");
		click_ansys(temp_click_id);
	})
	auto_step_1();
});

function menu_show(card_box_id)
{
	if(system.step>1 && system.step<5 && summon_state==0)
	{
	time_last=1;
	setTimeout(function(){time_last=0},1000)
	menu_reset();
	$("#triangle").hide();
	$("#flex_menu").hide();
	var card_id=get_card_id_from_box(card_box_id);
	if (card_box_id.substr(3,3)=="mon")
	{
		var temp_box=eval(card_box_id);
		if (temp_box.t==1){
		var box_order=parseInt(card_box_id[11]);
		var distance=distance_index(card_box_id);
		var ab_distance=parseInt(distance)+425;
		$(".menu").css
		({
			"bottom":"392px",
			"left":ab_distance+"px",
			"height":"60px",
		})
		setTimeout(function(){$("#triangle").slideDown();$("#flex_menu").fadeIn();},200);
	}		
	}
	if (card_box_id.substr(3,3)=="cov")
	{
		var temp_box=eval(card_box_id);
		if (temp_box.t==1){
		var box_order=parseInt(card_box_id[9]);
		var distance=distance_index(card_box_id);
		var ab_distance=parseInt(distance)+475;
		$(".menu").css
		({
			"bottom":"240px",
			"left":ab_distance+"px",
			"height":"60px",
			"width":"100px"
		})
		triangle.style.left="40px";
		document.getElementById("flex_menu").innerHTML="<img id=\"menu_effect\" class=\"in_menu\" src=\"img2/effect.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_effect')\">"
		setTimeout(function(){$("#triangle").slideDown();$("#flex_menu").fadeIn();},200);
	}
		
	}
	if (card_box_id.substr(3,3)=="han")
	{
		var box_order=parseInt(card_box_id[13]);
		var card_id=myself.hand_list[box_order-1];
		var distance=distance_index(card_box_id);
		var temp_card=get_card(card_id);
		if (temp_card.type=="monster")
		{	

			var ab_distance=parseInt(distance)+425;		
			$(".menu").css
			({
				"bottom":"100px",
				"left":ab_distance+"px",
				"height":"60px",
				"width":"200px",
			})
			triangle.style.left="85px";
			document.getElementById("flex_menu").innerHTML="<img id=\"menu_summon\" class=\"in_menu\" src=\"img2/summon.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_summon')\"><img id=\"menu_effect\" class=\"in_menu\" src=\"img2/effect.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_effect')\"><img id=\"menu_s_summon\" class=\"in_menu\" src=\"img2/s_summon.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_s_summon')\"><img id=\"menu_set\" class=\"in_menu\" src=\"img2/cover.png\" style=\"width:30px;height:30px;margin:8px\"onclick=\"click_ansys('menu_set')\">"
		}
		if (temp_card.type=="magic")
		{
			var ab_distance=parseInt(distance)+460;
			$(".menu").css
			({
				"bottom":"100px",
				"left":ab_distance+"px",
				"height":"60px",
				"width":"120px",
			})
			triangle.style.left="50px";
			document.getElementById("flex_menu").innerHTML="<img id=\"menu_effect\" class=\"in_menu\" src=\"img2/effect.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_effect_hand')\"><img id=\"menu_set\" class=\"in_menu\" src=\"img2/cover.png\" style=\"width:30px;height:30px;margin:8px\"onclick=\"click_ansys('menu_set')\">"
		}
		if (temp_card.type=="trap")
		{
			var ab_distance=parseInt(distance)+470;
			$(".menu").css
			({
				"bottom":"100px",
				"left":ab_distance+"px",
				"height":"60px",
				"width":"100px",
			})
			triangle.style.left="40px";
			document.getElementById("flex_menu").innerHTML="<img id=\"menu_set\" class=\"in_menu\" src=\"img2/cover.png\" style=\"width:30px;height:30px;margin:8px\"onclick=\"click_ansys('menu_set')\">"
		}
		setTimeout(function(){$("#triangle").slideDown();$("#flex_menu").fadeIn();},200);
		
	}}
	
}

function menu_hide()
{	
	$("#triangle").hide();
	$("#flex_menu").hide();
	$(".menu").css
		({
			"height":"0px",
		})
	setTimeout(function(){
		$(".menu").css
		({
			"transition":"height 0s",
            "-moz-transition":"height 0s", /* Firefox 4 */
            "-webkit-transition":"height 0s", /* Safari and Chrome */
            "-o-transition":"height 0s",/* Opera */
            "left":"425px",
            "top":"345px",
           })
	},300)
	setTimeout(function(){
		$(".menu").css
		({
			"transition":"height 0.3s",
	        "-moz-transition":"height 0.3s", /* Firefox 4 */
	        "-webkit-transition":"height 0.3s", /* Safari and Chrome */
	        "-o-transition":"height 0.3s",/* Opera */
	    })
	},301)
	document.getElementById("flex_menu").innerHTML="<img id=\"menu_turn\" class=\"in_menu\" src=\"img2/turn.png\" style=\"width:30px;height:30px;margin:8px\"><img id=\"menu_effect\" class=\"in_menu\" src=\"img2/effect.png\" style=\"width:30px;height:30px;margin:8px\"><img id=\"menu_attack\" class=\"in_menu\" src=\"img2/attack.png\" style=\"width:30px;height:30px;margin:8px\">"
}

function menu_reset()
{
	document.getElementById("reset_menu").innerHTML="<div id=\"menu\" class=\"menu\"><img id=\"triangle\" src=\"img2/triangle.png\" style=\"position:absolute;top:60px;left:90px;width:20px;height:30px;\"><div id=\"flex_menu\" class=\"flex_menu\"><img id=\"menu_turn\" class=\"in_menu\" src=\"img2/turn.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_turn')\"><img id=\"menu_effect\" class=\"in_menu\" src=\"img2/effect.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_effect')\"><img id=\"menu_attack\" class=\"in_menu\" src=\"img2/attack.png\" style=\"width:30px;height:30px;margin:8px\" onclick=\"click_ansys('menu_attack')\"></div></div>";
	$("#triangle").hide();
	$("#flex_menu").hide();

}
function random_box_id(type)
{
	var random_int=Math.floor(Math.random()*5+1);
	if (type=="mon")
	{
		var random_box="my_monster_"+random_int;
		var temp_box=eval(random_box)
		if (temp_box.t==1)
		{
			random_box_id(type);
		}
		else
		{
			return random_box;
		}
	}
	if (type=="cov")
	{
		var random_box="my_cover_"+random_int;
		var temp_box=eval(random_box);
		if (temp_box.t==1)
		{
			random_box_id(type);
		}
		else
		{
			return random_box;
		}
	}
}

var auto_list=[3,2,4,1,5]
function auto_box_id(type)
{
	var int=0;
	var auto_int=auto_list[int];
	if (type=="mon")
	{
		var auto_box="my_monster_"+auto_int;
	}
	else
	{
		var auto_box="my_cover_"+auto_int;
	}
	var temp_box=eval(auto_box)
	while (temp_box.t==1)
	{
		int++;
		var auto_int=auto_list[int];
		if (type=="mon")
		{
			var auto_box="my_monster_"+auto_int;
		}
		else
		{
			var auto_box="my_cover_"+auto_int;
		}
		var temp_box=eval(auto_box);
	}
	return auto_box;
}

var menu_state=0;
var last_click="";
var close_per=0;
var choose_list=[0,0];
function click_ansys(box_id)
{
	if (system.step<2)
	{return;}
	if (step_state==1)
	{
		ContextMenu();
	}
	if (box_id.substr(-2,1)=="_")
	{
		if (box_id.substr(3,3)=="mon" || box_id.substr(3,3)=="cov" || box_id.substr(3,3)=="han")
		{
			click_id=box_id;
			if (menu_state==0)
			{
				menu_show(box_id);
				menu_state=1;
			}
			else if (last_click==click_id)
			{
				menu_hide();
				menu_state=0;
			}
			else
			{
				menu_show(box_id);
				menu_state=1;
			}
			last_click=click_id;
		}
		else if (box_id.substr(6,3)=="mon" || box_id.substr(6,3)=="cov" || box_id.substr(6,3)=="han")
		{
			click_id=box_id;
		}
		close_per=0;
		setTimeout(function(){close_per=1},100)
	}
	else
	{
		if (menu_state==1 && close_per==1)
		{
			menu_hide(box_id);
			menu_state=0;
		}
	}
	var card_id=get_card_id_from_box(click_id);
	var temp_card=get_card(card_id);
	if (box_id=="menu_turn")
	{
		var temp_box=eval(click_id);
		if (temp_box.turn=="attack")
		{
			turn(click_id,'defend');
		}
		else
		{
			turn(click_id,"attack");
		}
		menu_hide();
	}
	if (box_id=="menu_effect_hand")
	{
		if (temp_card.type=="magic" && temp_card.value_require()==1)
		{
			menu_hide();
			var auto_box=auto_box_id("cov");
			execute_card(auto_box,click_id);
			execute(click_id);
			setTimeout(function(){into_cemetery(auto_box);},5000)
		}
	}
	if (box_id=="menu_summon")
	{
		menu_hide();
		var auto_box=auto_box_id("mon")
		summon_(auto_box,click_id,'attack');
	}
	if (box_id=="menu_set")
	{
		if (temp_card.type!="monster")
		{
			menu_hide();
			var auto_box=auto_box_id("cov");
			set_card(auto_box,click_id);
		}
		else
		{
			menu_hide();
			var auto_box=auto_box_id("mon");
			summon(auto_box,click_id,"cover");
		}
	}
	if (box_id=="menu_effect")
	{
		if (temp_card.type!="monster")
		{
			menu_hide();
			turn(click_id,"mg_face");
			execute(click_id);
			setTimeout(function(){into_cemetery(click_id);},5000)
		}
	}
	if (box_id=="menu_attack")
	{
		menu_hide();
		if (attack_permission!=1)
		{
			attack_step();
		}
		else
		{
			var temp_box=eval(click_id);
			if (enemy.monster_number==0 && temp_box.attack_permission==1)
			{
				var temp_damage=(-1)*temp_card.attack;
				enemy_life(temp_damage);
				msg_box2(temp_damage);
				temp_box.attack_permission=0;
			}
			else
			{
				choose_list[0]=click_id;
				setTimeout(function(){wait=1},100);
			}
		}
	}
	if (wait==1)
	{
		choose_list[1]=click_id;
		wait=0;
		attack(choose_list[0],choose_list[1]);
		choose_list=[0,0];
	}
}

function fix_size()
{
	var board_height=document.documentElement.clientHeight;
	var board_width=document.documentElement.clientWidth;
	var ratio_h=board_height/969;
	var ratio_w=board_width/1980;
	if (ratio_h>ratio_w)
	{
		var ratio=ratio_w;
	}
	else
	{
		var ratio=ratio_h;
	}
	var webFrame = require('electron').webFrame;
	webFrame.setZoomFactor(ratio);
}

//window.onresize=function()
//{
//	fix_size();
//}

window.oncontextmenu=ContextMenu;
var step_state=0
function ContextMenu()
{
	if (step_state==0 && list_per==0)
	{
		step_state=1;
		document.getElementById("step_box").style.height="300px";
	}
	else
	{
		step_state=0;
		document.getElementById("step_box").style.height="0px";
	}
	if (list_per==1)
	{
		document.getElementById("card_list").style.height="0px";
		window.onmousewheel=document.onmousewheel=function(){return false};
		list_per=0;
	}
	return false;  
}

var list_per=0;
var list_choose=[];
var list_temp=[];
function card_list(list,n)
{
	last_list=list;
	list_temp=list;
	if (list.length>0)
	{
		choose_state=1;
		window.onmousewheel=document.onmousewheel=scrollFunc; 
		$("#card_list").scrollLeft(0);
		document.getElementById("card_list").innerHTML="";
		if (list.length>5)
		{
			document.getElementById("card_list").style.width=1013+"px";
			document.getElementById("card_list").style.justifyContent="left";
		}
		else
		{
			document.getElementById("card_list").style.width=100+209*list.length+"px";
			document.getElementById("card_list").style.justifyContent="center";
		}
		document.getElementById("card_list").style.height="400px";
		list_per=1;
		var id0=list[0];
		var temp_card0=get_card(id0);
		var img0=temp_card0.img_src;
		list_choose=new Array(list.length);
		list_choose[0]=0;
		$("#card_list").append("<img id='list_0' class='card_list' src='"+img0+"'' onmouseover=\"interview('"+id0+"')\" onclick=\"choose_change(0,"+n+")\" style='margin-left:0px'>");
		for (var num=1;num<list.length;num++)
		{
			list_choose[num]=0;
			var id=list[num];
			var temp_card=get_card(id);
			var img=temp_card.img_src;
			$("#card_list").append("<img id='list_"+num+"' class='card_list' src='"+img+"'' onclick=\"choose_change("+num+","+n+")\" onmouseover=\"interview('"+id+"')\">");
		}
	}
}

var choose_state=0;
var choose_card=[];
function choose_change(id,n)
{
	var ids="list_"+id;
	if (list_choose[id]==0)
	{
		document.getElementById(ids).style.border="solid 10px orange";
		window.list_choose[id]=1;
	}
	else
	{
		document.getElementById(ids).style.border="solid 0px orange";
		window.list_choose[id]=0;
	}
	sum=0;
	for (var e=0;e<list_choose.length;e++)
	{
		if (list_choose[e]==1)
		{
			sum++;
		}
	}
	if (sum==n)
	{
		for (var e=0;e<list_choose.length;e++)
		{
			if (list_choose[e]==1)
			{
				choose_card.splice(0,0,list_temp[e]);
			}
		}
	}
}

var last_list=[]
function wheel(de)
{
	if (de>0)
	{
		var move_num=$("#card_list").scrollLeft()+104.9;
		if (move_num>(last_list.length-5)*209)
		{
			move_num=(last_list.length-5)*209;
		}
		$("#card_list").scrollLeft(move_num);
	}
	else
	{
		var move_num=$("#card_list").scrollLeft()-104.9;
		if (move_num<0)
		{
			move_num=0;
		}
		$("#card_list").scrollLeft(move_num);
	}
}

var scrollFunc=function(e)
{  
　　e=e || window.event;  
　　if (e.wheelDelta)
	{
		if (e.wheelDelta>0)
		{
			wheel(-1);  

    　　}
		if (e.wheelDelta<0)
		{
			wheel(1);
		}

　　}
	else if (e.detail)
	{
		if (e.detail>0)
		{
			wheel(-1);  

    　　}
		if (e.detail<0)
		{
			wheel(1);
		}
　　}  
　　if (document.addEventListener)
	{
		document.addEventListener('DOMMouseScroll',scrollFunc,false);
	}
}

function ad_change(ad,num,card_box_id)
{
	temp_box=eval(card_box_id);
	if (ad=="attack")
	{
		temp_box.attack+=num;
	}
	else
	{
		temp_box.defend+=num;
	}
	$("#"+card_box_id+">div").text(temp_box.attack+" "+temp_box.defend);
}